package com.dome.dao;

import com.dome.bean.DwBean;
import com.dome.bean.UserBean;
import com.dome.utils.JDBCutil;

import java.io.IOException;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class DwDao {

    public List<DwBean> findDws(String cdwName) throws SQLException, IOException, ClassNotFoundException {
        Connection conn= JDBCutil.getConnection();

        String sql="select * from dws ";
        if(cdwName!=null && !("".equals(cdwName))){
            sql +="where  dwName like '%"+cdwName+"%';";
        }
        System.out.println(sql);
        Statement stmt =conn.prepareStatement(sql);
        ResultSet set=stmt.executeQuery(sql);
        List<DwBean> list=new ArrayList<>();
        while (set.next()){
            int id=set.getInt("id");
            String  dwName=set.getString("dwName");
            String  dwUrl=set.getString("dwUrl");
            String  dwImg=set.getString("dwImg");
            String  mdesc=set.getString("mdesc");

            list.add(new DwBean(id,dwName,dwUrl,dwImg,mdesc));
        }
        conn.close();
        stmt.close();
        set.close();
        return list;
    }

}
